home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / actlib13.zip / CHECK.H < prev    next >
C/C++ Source or Header  |  1993-04-27  |  2KB  |  98 lines

  1. /***
  2.  *  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)
  3.  *
  4.  *  File        :  check.h
  5.  *
  6.  *  Description :  General macros for testing pre- and post-conditions.
  7.  *
  8.  *  OS/Compiler :  All
  9.  *
  10.  *  Decisions   :  Will use the tracing if defined
  11.  *
  12.  *  Usage       :  - To check a precondition call the function 
  13.  *                   'precond(  string_to_print, expression );'
  14.  *
  15.  *                 - Define 'PRE' to actually perform precondition check.
  16.  *
  17.  *                 - To check a postcondition call the function
  18.  *                   'postcond(  string_to_print, expression );'
  19.  *
  20.  *                 - Define 'POST' to actually perform postcondition check.
  21.  *
  22.  *                 - To check a condition call the function
  23.  *                   'check(  string_to_print, expression );'
  24.  *
  25.  *                 - Define 'CHECK' to actually perform check.
  26.  *
  27.  ***/
  28.  
  29.  
  30. #ifndef __Check_H
  31. #define __Check_H
  32.  
  33. #include "trace.h"
  34.  
  35. #ifdef TRACE
  36. #define ch_trace        trace
  37. #else
  38. #define ch_trace( args )    printf args
  39. #endif
  40.  
  41.         /*  MACROS DEFINITIONS  */
  42.  
  43.  
  44. #ifdef PRE
  45.  
  46. #define precond( test , expr ) \
  47.     if ( ! (expr) )                            \
  48.        { printf( "\n" ) ;                        \
  49.          ch_trace( ("*** " #test " : Precondition failed\n") ) ;    \
  50.          ch_trace( (" ** in file : " __FILE__ "\n") ) ;        \
  51.          ch_trace( (" ** at line : %d\n" , __LINE__) ) ;        \
  52.          ch_trace( (" ** '" #expr "' is false\n\n") ) ;        \
  53.        }
  54.  
  55. #else
  56.  
  57. #define precond( test , expr )
  58.  
  59. #endif
  60.  
  61. #ifdef POST
  62.  
  63. #define postcond( test , expr ) \
  64.     if ( ! (expr) )                            \
  65.        { printf( "\n" ) ;                        \
  66.          ch_trace( ("*** " #test " : Postcondition failed\n") ) ;    \
  67.          ch_trace( (" ** in file : " __FILE__ "\n") ) ;        \
  68.          ch_trace( (" ** at line : %d\n" , __LINE__) ) ;        \
  69.          ch_trace( (" ** '" #expr "' is false\n\n") ) ;        \
  70.        }
  71.  
  72. #else
  73.  
  74. #define postcond( test , expr )
  75.  
  76. #endif
  77.  
  78. #ifdef CHECK
  79.  
  80. #define check( test , expr ) \
  81.     if ( ! (expr) )                            \
  82.        { printf( "\n" ) ;                        \
  83.          ch_trace( ("*** " #test " : Check failed\n") ) ;        \
  84.          ch_trace( (" ** in file : " __FILE__ "\n") ) ;        \
  85.          ch_trace( (" ** at line : %d\n" , __LINE__) ) ;        \
  86.          ch_trace( (" ** '" #expr "' is false\n\n") ) ;        \
  87.        }
  88.  
  89. #else
  90.  
  91. #define check( test , expr )
  92.  
  93. #endif
  94.  
  95.  
  96.  
  97. #endif
  98.